package com.scvtc.service.office.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.entity.office.Examination;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.mapper.office.ExaminationMapper;
import com.scvtc.service.office.OfficeExaminationService;
import com.scvtc.utils.LikeQueryUtil;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service("OfficeExaminationService")
public class OfficeExaminationServiceImpl extends ServiceImpl<ExaminationMapper, Examination> implements OfficeExaminationService {

    @Override
    public ResResult<PageVo<List<Examination>>> getAllInfo(Long current, Long size, Examination Examination) {

        // 查询所有信息
        Page<Examination> page = page(new Page<>(current, size),
                LikeQueryUtil.likeQuery(Examination, Examination.class)
                        .lambda()
        );
//        Page<Examination> page= getBaseMapper().getAllInfo(new Page<Examination>(current, size));

        return ResResult.noMsgSuccess(new PageVo<>(page.getRecords(), page.getTotal()));
    }

    @Override
    public ResResult<?> addOneExamination(Examination Examination) {
        if (save(Examination)){
            return ResResult.success(Examination.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> updateExamination(Examination Examination) {
        if (updateById(Examination)){
            return ResResult.success(Examination.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteExamination(Long id) {
        if (removeById(id)){
            return ResResult.success();
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteMultipleExamination(Long[] ids) {
        if (removeByIds(Arrays.asList(ids))){
            return ResResult.success();
        }
        return ResResult.fail();
    }
}
